const fs = require('fs');

let p1 = new Promise((resolve, reject) => {
  fs.readFile('./files/a.txt', 'utf-8', (err, data) => {
    err ? reject(err) : resolve(data.length);
  })
})

let p2 = new Promise((resolve, reject) => {
  fs.readFile('./files/b.txt', 'utf-8', (err, data) => {
    err ? reject(err) : resolve(data.length);
  })
})

let p3 = new Promise((resolve, reject) => {
  fs.readFile('./files/c.txt', 'utf-8', (err, data) => {
    err ? reject(err) : resolve(data.length);
  })
})

// p.then().then().then()....

// 特点：前一个then返回Promise对象，Promise对象中的结果，会被下一个then得到

p1.then(res => {
  console.log(res); // 10
  return p2;
}).then(res => {
  console.log(res); // 13000
  return p3;
}).then(res => {
  console.log(res); // 5
})